package com.yjt.javatest.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yjt.javatest.entity.DTO.QuestionTestDTO;
import com.yjt.javatest.entity.QuestionTest;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (QuestionTest)表数据库访问层
 *
 * @author makejava
 * @since 2023-09-14 13:43:53
 */
@Mapper
public interface QuestionTestMapper extends BaseMapper<QuestionTest> {

    /**
     * @param questionId
     * @return
     */
    @Delete("delete from question_test where question_id = #{questionId}")
    Integer deleteByQuestionId(Long questionId);
    @Delete("delete from question_test where test_id = #{testId}")
    Integer deleteByTestId(Long testId);
    @Select("select max(`order`) from question_test where test_id = #{testId}")
    Long getMaxOrderByTestId(Long testId);

    @Insert("<script>" +
            "insert into question_test(test_id, question_id, `order`, score) values " +
            "<foreach collection = 'questionInfo' item = 'item' index = 'index' separator = ','>" +
            "(#{testId}, #{item.questionId}, #{item.order}, #{item.score})" +
            "</foreach>" +
            "</script>" )
    Integer addQuestions(Long testId, List<QuestionTestDTO> questionInfo);
}

